from __future__ import unicode_literals
from django.db import models
class usertable(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=64, null=False, unique=True)
    password = models.CharField(max_length=64, null=False)

    def __str__(self):
        return self.username

    class Meta:
        managed = True
        db_table = 'usertable'


Type = (
    (0, 'definition'),
    (1, 'formula'),
    (2, 'condition'),
    (3,'direction'),
)
Option = (
    (1, "A"),
    (2, "B"),
    (3, "C"),
    (4, "D"),
)


class exercise(models.Model):
    stem = models.CharField(max_length=1024, verbose_name="题干内容", blank=False, null=False)
    type = models.IntegerField(choices=Type, verbose_name="题目类型")

    class Meta:
        db_table = 'exercise'
        verbose_name = '题干表'


class options(models.Model):
    options = models.IntegerField(choices=Option, verbose_name="选项ABCD")
    content = models.CharField(max_length=256, verbose_name='选项内容')
    exercise = models.ForeignKey(exercise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'options'
        verbose_name = "选项表"
        unique_together = ('exercise', 'content')
        ordering = ['options']


class answer(models.Model):
    options = models.IntegerField(choices=Option, verbose_name="选项ABCD")
    exercise = models.ForeignKey(exercise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'answer'
        verbose_name = "答案表"
        unique_together = ('exercise', 'options')
        ordering = ['options']


class Test_Paper(models.Model):
    class Meta:
        db_table = 'test_paper'


class Test_Paper_Exercise(models.Model):
    stem = models.CharField(max_length=254, verbose_name='题干内容', blank=False, null=False, unique=True)
    type = models.IntegerField(choices=Type, verbose_name='题目类型')
    test_paper = models.ForeignKey(Test_Paper, on_delete=models.CASCADE)

    class Meta:
        db_table = 'test_paper_exercise'
        verbose_name = '题干表'


class Test_Paper_options(models.Model):
    options = models.IntegerField(choices=Option, verbose_name='选项ABCD')
    content = models.CharField(max_length=256, verbose_name='选项内容')
    exercise = models.ForeignKey(Test_Paper_Exercise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'test_paper_options'
        verbose_name = '选项表'
        unique_together = ('exercise', 'content')
        ordering = ['options']


class Test_Paper_Answer(models.Model):
    options = models.IntegerField(choices=Option, verbose_name='选项ABCD')
    exercise = models.ForeignKey(Test_Paper_Exercise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'test_paper_answer'
        verbose_name = '答案表'
        unique_together = ('exercise', 'options')
        ordering = ['options']


class summary(models.Model):
    yourchoice = models.IntegerField(choices=Option, verbose_name='选项ABCD', null=True)
    exercise = models.ForeignKey(Test_Paper_Exercise, on_delete=models.CASCADE,null=True)

    # type = models.IntegerField(choices=Type, verbose_name='题目类型',null=True)

    class Meta:
        db_table = 'summary'
        verbose_name = '所选选项表'
        unique_together = ('exercise', 'yourchoice')
        ordering = ['yourchoice']
